import axios from "axios";
import { Message } from "element-ui";
// import store from "../store/user";

const instance = axios.create({
    // baseURL:baseUrl,
    // baseURL: 'http://192.168.3.141:8000',
    // baseURL: 'http://192.168.3.248:8000',
    baseURL: 'http://192.168.3.142:9091',
    // baseURL: 'http://192.168.3.145',
    // baseURL: 'http://192.168.3.75:8000',
    // baseURL: 'http://192.168.3.14:8000',
    // baseURL: 'http://192.168.3.198:8000',

    // baseURL: window.location.origin,
    timeout: 50000,
    // 生产环境为true
    isOnProduce: true,
    // 是否本地存储
    isLocalStorage: true,
})

instance.interceptors.request.use(
    // 请求拦截
    (config) => {
        // let token = sessionStorage.getItem('userToken')
        // config.headers['Authorization'] = 'Bearer ' + token
        // let a = JSON.parse(sessionStorage.getItem('selectTite'))
        // let b = sessionStorage.getItem('opType')
        // if (a) {
        //     // console.log(a[0]);
        //     if (a.length == 1) {
        //         config.headers['operateModule'] = encodeURIComponent(a[0])

        //     } else if (a.length == 2) {
        //         config.headers['operateModule'] = encodeURIComponent(a[0] + '-' + a[1])

        //         // config.headers['operateModule'] = encodeURIComponent(a[0])+'-'+encodeURIComponent(a[1])

        //     } else {
        //         config.headers['operateModule'] = encodeURIComponent(a[0] + '-' + a[1] + '-' + a[2])

        //     }
        // }
        // if (b) {
        //     config.headers['operateType'] = b
        // }
        return config
    },
    (err) => {
        return Promise.reject(err)
    }
)
instance.interceptors.response.use(
    // 响应拦截
    (response) => {

        if (response.data.code == 2000) {
            // 操作
            return response.data
        }
        else {
            return response.data;
        }
    },
    (err) => {
        console.log('错误信息', err);
        return Promise.reject(err)
    }
)
export default instance